﻿using Batman.DLL.UserModule.Models;
using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;
using System.Collections.Generic;
using System.Linq;
using Secret = IdentityServer4.Models.Secret;

namespace Batman.DLL.UserModule
{
    public class Default
    {
        public static List<TestUser> GetUsers()
        {
            return new List<TestUser>()
            {
                new TestUser
                {
                    SubjectId="1",
                    Username="admin",
                    Password="admin@123"
                }
            };
        }

        public static List<Role> GetRoles()
        {
            return new List<Role>()
            {
                new Role()
                {
                     Name = "管理员"
                }
            };
        }


        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile()
            };
        }

        public static IEnumerable<ApiScope> GetApiScopes() => new ApiScope[]
        {
                new ApiScope("scope","授权认证服务器接口范围"),
                new ApiScope(IdentityServerConstants.LocalApi.ScopeName, ""), 
        };

        public static IEnumerable<ApiResource> GetApiResources()
        {
            return new List<ApiResource>
            {
                new ApiResource("api", "授权认证服务器接口")
                {
                    Scopes = { GetApiScopes().First().Name}
                },
                new ApiResource(IdentityServerConstants.LocalApi.ScopeName, "认证服务器本地接口")
                {
                    Scopes = { GetApiScopes().First(t=>t.Name== IdentityServerConstants.LocalApi.ScopeName).Name}
                }
            };
        }

        public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                new Client
                {
                    ClientId = "C0001",
                    ClientName = "授权服务器客",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,

                    ClientSecrets = { new Secret("C0001_secret".Sha256()) },

                    AllowedScopes =
                    {
                        "scope", "openid", "profile", IdentityServerConstants.LocalApi.ScopeName
                    },
                    AllowOfflineAccess = true
                }
            };
        }


    }
}
